<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/2/19 0019
 * Time: 22:45
 */
$server = new Swoole\Server('0.0.0.0', 9502, SWOOLE_PROCESS, SWOOLE_SOCK_TCP);

$server->set([
    'worker_num'=>1,
    'heartbeat_idle_time' => 600,
    'heartbeat_check_interval' => 60
]);
$server->on('connect', function ($serv, $fd) {
    echo "有新的客户端连接，连接标识为$fd" . PHP_EOL;
});

$server->on('receive', function ($serv, $fd, $from_id, $data) {
    //向服务端1的客户端发送数据
    $serv->send($fd, $data + 1);

});

$server->on('close', function ($serv, $fd) {
    echo "编号为{$fd}的客户端已经关闭." . PHP_EOL;
});


$server->start();